package edu.hawaii.myisern.model;


/**
 * User for the login/login security system of myIsern site.
 * 
 * Attributed and Inspired by Tim Fennell.
 * 
 * @author Jon Lao
 * @author Jared Sunouchi
 * @author Chiao-Fen Zielinski-Liu
 */
public class User {
  
  private Integer id;
  private String username;
  private String password;
  private static final String hashBaseInput = "myISERN";
  private static final int hashBase = hashBaseInput.hashCode(); 
  
  /** 
   * Default constructor.
   *  
   */
  public User() { 
    // default constructor. 
  }

  /**
   * Constructs a well formed user.
   * 
   * @param username of user
   * @param password of user
   */
  public User(String username, String password) {
    this.username = username;
    this.password = password;
  }

  /**
   * Gets the ID of the user.
   * 
   * @return id of user.
   */
  public Integer getId() {
    return id;
  }

  /**
   * Sets the ID of the user.
   * 
   * @param id of user
   */
  public void setId(Integer id) {
    this.id = id;
  }

  /**
   * Gets the username of the person.
   * 
   * @return username of user
   */
  public String getUsername() {
    return username;
  }

  /**
   * Sets the username of the user.
   * 
   * @param username of user
   */
  public void setUsername(String username) {
    this.username = username;
  }

  /**
   * Gets the person's unencrypted password.
   * 
   * @return password of user
   */
  public String getPassword() {
    return password;
  }

  /**
   * Sets the person's unencrypted password.
   * 
   * @param password of user
   */
  public void setPassword(String password) {
    this.password = password;
  }

  /**
   * Checks if the user IDs are same.
   * Overrides Object equal method. 
   * 
   * @param obj object to compare.
   * @return true if equal objects equal.
   */
  @Override public boolean equals(Object obj) {
    return (obj instanceof User) && this.id == ((User) obj).id;
  }

  /**
   * Hash code for the equals override.
   * 
   * @return the hash code.
   */
  @Override public int hashCode() {
    int hash = hashBase;
    
    hash = hash * 5 + this.id;
    hash = hash * 5 + this.id;
    hash = hash * 5 + this.id;    
    
    return hash;
  } 
}
